<?php
header("Content-type:text/html;charset=utf-8");
include '../../api/config.php';
include './item_file.php';
$data = file_get_contents('php://input');

if ($data) {
    $d = json_decode($data);
    $token = $d->token;
    $sql = "SELECT * FROM admin_user WHERE token='{$token}'";
    $stmt1 = $conn->query($sql);
    $stmt1->execute();
    $result1 = $stmt1->setFetchMode(PDO::FETCH_ASSOC);
    $result1 = new RecursiveArrayIterator($stmt1->fetchAll());
    $user_name = $result1[0]['name'];
    $book_id = false;
    if ($user_name) {
        if ($book_id) {
            $sql_1 = "SELECT * FROM book WHERE id='{$id}'";
            $stmt = $conn->query($sql_1);
            $stmt->execute();
            $result = new RecursiveArrayIterator($stmt->fetchAll());
            alert($result[0]);
            include './file_item_index.php';
        } else {
            $sql_2 = "SELECT * FROM book";
            $stmt = $conn->query($sql_2);
            $stmt->execute();
            $result = new RecursiveArrayIterator($stmt->fetchAll());
            $len = count($result);
            for ($i = 0; $i < $len; $i++) {
                alert($result[$i]);
            };
            include './file_item_index.php';
        }
    } else {
        echo "<script>\r\n    window.location.href = '../../';\r\n    </script>";
    }
} else {
    echo "<script>\r\n    window.location.href = '../../';\r\n    </script>";
}
$conn = null;